class Solution:
    def search(self, nums: List[int], target: int) -> int:
        def bisearch(nums,target,offset):
            head=0
            tail=len(nums)-1
            while head<=tail:
                temp=(head+tail)//2
                if nums[temp]>target:
                    tail=temp-1
                elif nums[temp]<target:
                    head=temp+1
                else:
                    return temp+offset
            return -1
        def nosearch(nums,target):
            for i,val in enumerate(nums):
                if val==target:
                    return i
            return -1
        if len(nums)<3:
            return nosearch(nums,target)
        try:
            for i in range(len(nums)):
                if nums[i]>nums[i+1]:
                    edge = i+1
                    break
        except IndexError:
            edge=len(nums)
        if target<nums[0]:
            return bisearch(nums[edge:],target,edge)
        elif target>nums[0]:
            return bisearch(nums[:edge],target,0)
        else:
            return 0